﻿
using System;
using System.Xml.Linq;
namespace sharpxbot.Core.Configuration
{
    public class XmlGroupChatConfiguration : IGroupChatConfiguration
    {
        #region IGroupChatConfiguration Members

        public string RoomJid { get; private set; }

        public string ResourceName { get; private set; }

        #endregion

        public XmlGroupChatConfiguration(XElement configElement)
        {
            if (configElement == null)
                throw new NullReferenceException("Group chat config can't be null");

            foreach (var child in configElement.Elements())
            {
                switch (child.Name.LocalName)
                {
                    case "jid":
                        RoomJid = child.Value;
                        break;
                    case "resource":
                        ResourceName = child.Value;
                        break;
                }
            }

            if (String.IsNullOrWhiteSpace(RoomJid) || String.IsNullOrWhiteSpace(ResourceName))
                throw new OperationCanceledException("Mailformed group chat config section");
        }
    }
}
